var api = require('../../config/api.js');
var util = require('../../utils/util.js');
var quantity = require('../components/quantity/quantity.js');
var app = getApp();
Page({
  data: {
	  scrollLeft: 0,
	  navList: [],
	  navIndex:0,
	  banners: []
  },
  onLoad: function onLoad(options) {
	 var navList = [];
	 for(var i=0;i<10;i++){
		 var nav = {title:'分类啊'+i};
		 navList.push(nav);
	 }
	 
	 this.setData({
		 navList: navList
	 });
	 
	 var banners = [];
	 for(var i=0;i<10;i++){
		 var banner = {picUrl:'https://cdn.it120.cc/apifactory/2017/11/17/4eed2ccae3178578326f3adcd60a7b06.jpg'};
		 banners.push(banner);
	 }
	 this.setData({
		 banners: banners
	 });
  },
  onShow: function onShow() {
	// 页面显示触发
  },
  //显示对话框
  showModal: function () {
	  quantity.default.toggleDialog(this);
  },
  //隐藏对话框
  toggleDialog: function () {
	  quantity.default.toggleDialog(this);
  },
  showLoading: function showLoading(){
	  this.setData({
		  loadFlg: true 
	  });
  },
  hideLoading: function hideLoading(){
	  this.setData({
		  loadFlg: false 
	  });
  },
  switchNav: function switchNav(event){
	  var index = event.target.dataset.index;
	  var scrollLeft = this.data.scrollLeft;
	  if(scrollLeft < 0){
		  scrollLeft = 0;
	  }
	  
	  var navIndex = this.data.navIndex;
	  if(index > navIndex){
		  var lx = 60*(index-navIndex);
		  this.setData({
			  navIndex: index,
			  scrollLeft: scrollLeft+lx
		  });
	  }
	  if(index < navIndex){
		  var lx = 60*(navIndex-index);
		  this.setData({
			  navIndex: index,
			  scrollLeft: scrollLeft-lx
		  });
	  }
	  
  }
  
});